import { IPSModelSortable } from '../../ipsmodel-sortable';
import { IPSDataEntity } from '../ipsdata-entity';
import { IPSDEFGroup } from '../defield/ipsdefgroup';
import { IPSDEDQMain } from './ipsdedqmain';
import { IPSDEDataQuery } from './ipsdedata-query';
import { IPSDEDataQueryCode } from './ipsdedata-query-code';
import { IPSDEDataQueryInput } from './ipsdedata-query-input';
import { IPSDEDataQueryReturn } from './ipsdedata-query-return';
import { PSModelObjectImpl } from '../../psmodel-object-impl';

export class PSDEDataQueryImpl extends PSModelObjectImpl implements IPSDEDataQuery, IPSModelSortable {
  protected allpsdedataquerycodes: IPSDEDataQueryCode[] | null = null;

  getAllPSDEDataQueryCodes(): IPSDEDataQueryCode[] | null {
    if (this.allpsdedataquerycodes == null) {
      this.allpsdedataquerycodes = this.fillChildListModel(this.M.getAllPSDEDataQueryCodes, 'dataentity.ds.IPSDEDataQueryCode') as IPSDEDataQueryCode[];
    }
    return this.allpsdedataquerycodes;
  }

  get allPSDEDataQueryCodes(): IPSDEDataQueryCode[] | null {
    return this.getAllPSDEDataQueryCodes();
  }

  findPSDEDataQueryCode(objKey: any): IPSDEDataQueryCode | null {
    return this.getPSModel5('dataentity.ds.IPSDEDataQueryCode', this.getAllPSDEDataQueryCodes(), objKey) as IPSDEDataQueryCode;
  }

  get codeName(): string {
    return this.M.codeName;
  }

  get dEFGroupType(): 'FIELDS' | 'FORMITEMS' | 'BASEFIELDS' | 'AUDITFIELDS' {
    return this.M.dEFGroupType;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  get extendMode(): 0 | 2 {
    return this.M.extendMode != null ? this.M.extendMode : 0;
  }

  get logicName(): string {
    return this.M.logicName;
  }

  get memo(): string {
    return this.M.memo;
  }

  get name(): string {
    return this.M.name;
  }

  get orderValue(): number {
    return this.M.orderValue != null ? this.M.orderValue : 99999;
  }

  protected psdedqmain: IPSDEDQMain | null = null;

  getPSDEDQMain(): IPSDEDQMain | null {
    if (this.psdedqmain != null) return this.psdedqmain;
    const value = this.M.getPSDEDQMain;
    if (value == null) {
      return null;
    }
    this.psdedqmain = this.getPSModel4('dataentity.ds.IPSDEDQMain', value, 'getPSDEDQMain') as IPSDEDQMain;
    return this.psdedqmain;
  }

  get psDEDQMain(): IPSDEDQMain | null {
    return this.getPSDEDQMain();
  }

  getPSDEDQMainMust(): IPSDEDQMain {
    const value = this.getPSDEDQMain();
    if (value == null) {
      throw new Error('未指定查询主表对象');
    }
    return value;
  }

  protected psdedataqueryinput: IPSDEDataQueryInput | null = null;

  getPSDEDataQueryInput(): IPSDEDataQueryInput | null {
    if (this.psdedataqueryinput != null) return this.psdedataqueryinput;
    const value = this.M.getPSDEDataQueryInput;
    if (value == null) {
      return null;
    }
    this.psdedataqueryinput = this.getPSModel4('dataentity.ds.IPSDEDataQueryInput', value, 'getPSDEDataQueryInput') as IPSDEDataQueryInput;
    return this.psdedataqueryinput;
  }

  get psDEDataQueryInput(): IPSDEDataQueryInput | null {
    return this.getPSDEDataQueryInput();
  }

  getPSDEDataQueryInputMust(): IPSDEDataQueryInput {
    const value = this.getPSDEDataQueryInput();
    if (value == null) {
      throw new Error('未指定调用输入对象');
    }
    return value;
  }

  protected psdedataqueryreturn: IPSDEDataQueryReturn | null = null;

  getPSDEDataQueryReturn(): IPSDEDataQueryReturn | null {
    if (this.psdedataqueryreturn != null) return this.psdedataqueryreturn;
    const value = this.M.getPSDEDataQueryReturn;
    if (value == null) {
      return null;
    }
    this.psdedataqueryreturn = this.getPSModel4('dataentity.ds.IPSDEDataQueryReturn', value, 'getPSDEDataQueryReturn') as IPSDEDataQueryReturn;
    return this.psdedataqueryreturn;
  }

  get psDEDataQueryReturn(): IPSDEDataQueryReturn | null {
    return this.getPSDEDataQueryReturn();
  }

  getPSDEDataQueryReturnMust(): IPSDEDataQueryReturn {
    const value = this.getPSDEDataQueryReturn();
    if (value == null) {
      throw new Error('未指定调用返回对象');
    }
    return value;
  }

  protected psdefgroup: IPSDEFGroup | null = null;

  getPSDEFGroup(): IPSDEFGroup | null {
    if (this.psdefgroup != null) return this.psdefgroup;
    const value = this.M.getPSDEFGroup;
    if (value == null) {
      return null;
    }
    const ipsdataentity = this.getParentPSModelObject('dataentity.IPSDataEntity') as IPSDataEntity;
    if (ipsdataentity != null) {
      this.psdefgroup = ipsdataentity.findPSDEFGroup(value);
    }
    return this.psdefgroup;
  }

  get psDEFGroup(): IPSDEFGroup | null {
    return this.getPSDEFGroup();
  }

  getPSDEFGroupMust(): IPSDEFGroup {
    const value = this.getPSDEFGroup();
    if (value == null) {
      throw new Error('未指定属性组');
    }
    return value;
  }

  get userCat(): string {
    return this.M.userCat;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  get viewLevel(): -1 | 0 | 1 | 2 | 3 | 100 {
    return this.M.viewLevel != null ? this.M.viewLevel : -1;
  }

  get customCode(): boolean {
    return this.M.customCode != null ? this.M.customCode : false;
  }

  get defaultMode(): boolean {
    return this.M.defaultMode != null ? this.M.defaultMode : false;
  }

  get privQuery(): boolean {
    return this.M.privQuery != null ? this.M.privQuery : false;
  }

  get pubServiceDefault(): boolean {
    return this.M.pubServiceDefault != null ? this.M.pubServiceDefault : false;
  }

  get queryFromView(): boolean {
    return this.M.queryFromView != null ? this.M.queryFromView : false;
  }

  get cls(): string {
    return 'PSDEDataQueryImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'IPSModelSortable' || cls == 'dataentity.ds.IPSDEDataQuery') return true;
    return super.instanceof(cls);
  }
}
